package com.sgchen.security.util;


import com.sgchen.security.annotation.EncryptController;
import com.sgchen.security.annotation.EncryptRequest;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerExecutionChain;


/**
 * 签名
 *
 * @author sgchen
 */
public class RequestFilterUtil {

    private RequestFilterUtil() {
    }

    /**
     * 判断是否需要加解密
     *
     * @param handler
     * @return
     */
    public static boolean hasDecryptAnnotation(HandlerExecutionChain handler) {
        if (handler == null) {
            return false;
        }
        if (handler.getHandler() instanceof HandlerMethod) {
            HandlerMethod handlerMethod = (HandlerMethod) handler.getHandler();
            return handlerMethod.getMethodAnnotation(EncryptRequest.class) != null || handlerMethod.getBeanType().isAnnotationPresent(EncryptController.class);
        }
        return false;
    }

}
